<?php
namespace model;

use think\Model;

class Role extends Model{

    public function permissions(){
        return $this->hasMany('RolePermission', 'rid');
    }

    public function getPermissionArrayAttr($value, $data){
        $permissions = [];
        $tmp = self::permissions()->select();
        foreach($tmp as $v){
            $permission = $v->permission()->find();
            $permissions[$permission->module]["{$permission->controller}:{$permission->icon}"][$permission->action] = ['id' => $permission->id, 'name' => $permission->name];
        }
        return $permissions;
    }
}